/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package databasemini;

import dao.ExecDeleteQuery;
import dao.ExecInsertQuery;
import dao.ExecQuery;
import dao.ExecRowXML;
import dao.ExecSelectQuery;
import dao.ExecTableXML;
import dao.ExecUpdateQuery;
import dao.ExecXML;
import gui.MainFrame;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import pojo.Message;
import pojo.Property;
import pojo.QueryInfo;
import pojo.Row;

/**
 *
 * @author HoangLiem
 */
public class DatabaseMini {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws ParserConfigurationException {
        //Thu truy van insert
        /*String query1 = "insert  into Lop ( MaLop , TenLop ) values(  4, 'Lop 04')";
        String query2 = "INSERT  into Lop ( MaLop , TenLop ) values(  4, 'Lop 04')";
        String query3 = "insert  into Lop ( MaLop , TenLop ) VALUES(  5, 'Lop 05, 23')";
        Message message = new Message("");
        // ExecInsertQuery.validateAndExecQuery("quanlysinhvien", query3, message);
        //  System.out.println(message.getMessage());
        StringBuilder sb = new StringBuilder("hello");
        System.out.println(sb.length());
         */
        //thu truy van delete
        /*
        String queryDelete1 = "delete   from   sinhvien   where masinhvien='09' or masinhvien='10'";
        String queryDelete2 = "delete   from   lop   WHERE MaLop=4 or MaLop=5";
        String databaseName = "quanlysinhvien";
        Message message = new Message("");
        boolean b = ExecDeleteQuery.validateAndExecQuery(databaseName, queryDelete1, message);
        System.out.println(b);
        System.out.println(message.getMessage());
         */

        /*
        ArrayList<String> conPro = new ArrayList<String>();
        conPro.add("malop");
        ArrayList<String> conData = new ArrayList<String>();
        conData.add("3");     
        ArrayList<String> upPro = new ArrayList<String>();
        upPro.add("tenLop");
        ArrayList<String> upData = new ArrayList<String>();
        upData.add("lop 03");      
        QueryInfo con = new QueryInfo(conPro, conData);
        QueryInfo data = new QueryInfo(upPro, upData);
        int n = ExecRowXML.updateRow("quanlysinhvien", "lop", con, data);     
        System.out.println(n + " row updated");
         */

        /*
        //thu truy van update
        String queryUpdate = "update lop set tenlop='lop 03 update'where malop=3";
        Message message = new Message("");
        boolean b = ExecUpdateQuery.validateAndExecQuery("quanlysinhvien", queryUpdate, message);
        System.out.println(b);
        System.out.println(message.getMessage());
         */


        // Thu nghiem checkdeleteRow
        Document doc = ExecXML.getDocument("quanlysinhvien.xml");
        String xpath = "database/table[@name='sinhvien']/row[@malop='3']";
        Node node = (Node) ExecXML.execXpathReturnNode(doc, xpath);
        Element e = (Element) node;
        //System.out.println(e.getAttribute("tenlop"));
        boolean b = ExecRowXML.isExistedFkValue("quanlysinhvien", "sinhvien", e);

        // Thu nghiem checkselectwithstar
        String query = "select *From A where a='b'";
        Message message = new Message();
        boolean a = ExecSelectQuery.CheckQuerySelectWithStar(query, message);
        System.out.println(a);
        ArrayList<String> demo = ExecQuery.splitWhere(query);
        for (int i = 0; i < demo.size(); i++) {
            System.out.println(demo.get(i));
        }
        System.out.println(message.getMessage());
        
        /*Document doc = ExecXML.getDocument("quanlysinhvien.xml");
        ArrayList<String> proNames = new ArrayList<String>();
        ArrayList<String> proData = new ArrayList<String>();
        proNames.add("TenLop");
        proData.add("lop 03");
        System.out.println(ExecRowXML.deleteRow("quanlysinhvien", "lop", proNames, proData));
        
         */
        //Khu này show phần giao diện
        /*javax.swing.SwingUtilities.invokeLater(new Runnable() {
        
        public void run() {
        try {
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (ClassNotFoundException ex) {
        Logger.getLogger(DatabaseMini.class.getName()).log(Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
        Logger.getLogger(DatabaseMini.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
        Logger.getLogger(DatabaseMini.class.getName()).log(Level.SEVERE, null, ex);
        } catch (UnsupportedLookAndFeelException ex) {
        Logger.getLogger(DatabaseMini.class.getName()).log(Level.SEVERE, null, ex);
        }
        MainFrame frm = new MainFrame();
        frm.setExtendedState(JFrame.MAXIMIZED_BOTH);
        frm.setVisible(true);
        }
        });*/
    }
}
